import QtQuick 1.1
import com.nokia.meego 1.0
import TransferUI 1.0
import "Consts.js" as Constants

Item {
    id: transferEditor

    property alias id: idTextField.text
    property alias name: nameTextField.text
    property alias targetName: targetNameTextField.text
    property int size: sizeTextField.text
    property int type: Constants.TransferType.Upload
    property alias typeButtonsEnabled: typeButtonColumn.enabled
    property alias registerButtonEnabled: registerButton.enabled
    property alias commitButtonEnabled: commitButton.enabled

    property Style platformStyle: LabelStyle {}

    signal registerButtonClicked()
    signal commitButtonClicked()

    onSizeChanged: {
        sizeTextField.text = size;
    }

    Grid {
        id: editorGrid
        width: parent.width
        property int firstColumnWidth: 150
        property int secondColumnWidth: parent.width - spacing / 2
                                        - firstColumnWidth

        anchors {
            top: parent.top
            left: parent.left
            right: parent.right
        }

        columns: 2
        spacing: 10

        Text {
            width: editorGrid.firstColumnWidth
            height: idTextField.height
            verticalAlignment: Text.AlignVCenter
            text: "ID"

            font {
                family: platformStyle.fontFamily
                pixelSize: platformStyle.fontPixelSize
            }
        }
        TextField {
            id: idTextField
            width: editorGrid.secondColumnWidth
        }

        Text {
            width: editorGrid.firstColumnWidth
            height: nameTextField.height
            verticalAlignment: Text.AlignVCenter
            text: "Name"

            font {
                family: platformStyle.fontFamily
                pixelSize: platformStyle.fontPixelSize
            }
        }
        TextField {
            id: nameTextField
            width: editorGrid.secondColumnWidth
        }

        Text {
            width: editorGrid.firstColumnWidth
            height: targetNameTextField.height
            verticalAlignment: Text.AlignVCenter
            text: "Target name"

            font {
                family: platformStyle.fontFamily
                pixelSize: platformStyle.fontPixelSize
            }
        }
        TextField {
            id: targetNameTextField
            width: editorGrid.secondColumnWidth
        }

        Text {
            width: editorGrid.firstColumnWidth
            height: sizeTextField.height
            verticalAlignment: Text.AlignVCenter
            text: "Size"

            font {
                family: platformStyle.fontFamily
                pixelSize: platformStyle.fontPixelSize
            }
        }
        TextField {
            id: sizeTextField
            width: editorGrid.secondColumnWidth
            validator: IntValidator {}
            inputMethodHints: Qt.ImhPreferNumbers

            onTextChanged: {
                var textAsNum = sizeTextField.text;
                transferEditor.size = textAsNum;
            }
        }

        Text {
            width: editorGrid.firstColumnWidth
            height: typeButtonColumn.height
            verticalAlignment: Text.AlignVCenter
            text: "Type"

            font {
                family: platformStyle.fontFamily
                pixelSize: platformStyle.fontPixelSize
            }
        }
        ButtonColumn {
            id: typeButtonColumn
            width: editorGrid.secondColumnWidth
            checkedButton: uploadButton

            Button {
                id: uploadButton
                text: "Upload"
                onClicked: transferEditor.type = Constants.TransferType.Upload;
            }
            Button {
                id: downloadButton
                text: "Download"
                onClicked: transferEditor.type = Constants.TransferType.Download;
            }
            Button {
                id: syncButton
                text: "Sync"
                onClicked: transferEditor.type = Constants.TransferType.Sync;
            }
        }
    }

    Row {
        id: buttonRow

        anchors {
            top: editorGrid.bottom
            left: parent.left
            right: parent.right
            topMargin: 20
        }

        spacing: 10

        Button {
            id: registerButton
            width: (buttonRow.width - buttonRow.spacing) / 2
            text: "Register"
            onClicked: transferEditor.registerButtonClicked();
        }
        Button {
            id: commitButton
            width: registerButton.width
            text: "Commit"
            onClicked: transferEditor.commitButtonClicked();
        }
    }
}

// End of file.
